Skip to content

fix(ci): get the test suite green — provision Postgres, track migrations, harden JWT secret#4

Merged
austinchima merged 3 commits into
masterfrom
fix/ci-postgres-test-failures
Jun 28, 2026
Merged

fix(ci): get the test suite green — provision Postgres, track migrations, harden JWT secret#4
austinchima merged 3 commits into
masterfrom
fix/ci-postgres-test-failures

Conversation

@austinchima

@austinchima austinchima commented Jun 28, 2026

Copy link
Copy Markdown
Owner

Summary

Gets the CI test suite passing. Before this branch, all 52 DB-backed tests failed with 42P01: relation "AspNetUsers"/"RefreshTokens" does not exist (unit) and 503 Service Unavailable (integration).

Root cause

Two layered problems:

  1. Tests started their own Testcontainers Postgres, which doesn't work on the CI runner without Docker-in-Docker.
  2. More fundamentally, the Migrations/ folder was listed in .gitignore, so the EF Core migration classes were never committed. In CI the fresh checkout compiled Precept.Api with zero Migration classes, so MigrateAsync() found nothing to apply and silently no-op'd — leaving every per-test-class database schemaless. It passed locally only because the migration files exist in the working tree on disk.

Changes

  • fix(ci): use CI-provisioned Postgres for test database — the shared PostgresContainerFixture now respects ConnectionStrings__PreceptDb when set, so CI uses the action-setup-postgres service and falls back to Testcontainers locally. Per-class isolated databases are still created on the chosen server.
  • fix(ci): track EF Core migrations in git — remove the Migrations/ ignore rule and commit the existing migrations so CI provisions the schema the same way local runs do.
  • fix(security): fail fast when JWT signing key is missing or too weak — validate JwtSettings:SecretKey at startup (present, ≥32 bytes for HMAC-SHA256) so a misconfigured deploy throws a clear error at boot instead of an obscure failure on the first token-signing request.

Verification

  • dotnet build (Release) clean, 0 warnings.
  • The integration harness sets a 53-byte test JWT secret, so the new startup guard clears the 32-byte floor and won't trip CI.

Follow-up (not in this PR)

  • forgot-password (AuthController.cs:366) generates a reset token but has no email provider wired up — password reset is a no-op in production until one is added.

🤖 Generated with Claude Code

austinchima and others added 3 commits June 28, 2026 01:17
Tests were starting their own Testcontainers Postgres container, which
failed or connected to an un-migrated DB in GitHub Actions. Make the
shared PostgresContainerFixture respect ConnectionStrings__PreceptDb
when present, so CI uses the action-setup-postgres service.

- PostgresContainerFixture falls back to Testcontainers locally
- Per-class isolated databases are still created on the chosen server
- Workflow sets the env var only for the test step
The Migrations/ folder was gitignored, so the migration classes never
reached GitHub. In CI the fresh checkout compiled Precept.Api with zero
Migration classes, so MigrateAsync() found nothing to apply and silently
no-op'd — leaving every per-test-class database schemaless. All 52
DB-backed tests failed with 42P01 "relation does not exist" (unit) or
503 Service Unavailable (integration).

Remove the Migrations/ ignore rule and commit the existing migrations so
CI provisions the schema the same way local runs do.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Previously a missing or short JwtSettings:SecretKey surfaced only as an
obscure error on the first token-signing request. Validate at startup that
the key is present and at least 32 bytes (256 bits, the HMAC-SHA256
minimum), throwing a clear InvalidOperationException at boot otherwise.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@austinchima austinchima changed the title fix(ci): use CI-provisioned Postgres for test database fix(ci): get the test suite green — provision Postgres, track migrations, harden JWT secret Jun 28, 2026
@austinchima austinchima merged commit 54e0016 into master Jun 28, 2026
3 checks passed
@austinchima austinchima deleted the fix/ci-postgres-test-failures branch June 28, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant